package controller;

import moder.Pager;
import moder.TbProduct;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/pager.do")
public class ProductPagerController extends HttpServlet {
    dao.TbProductDao gs = new dao.impl.TbProductDaoImpl();
    service.TbProductService productService = new service.impl.TbProductServiceImpl();
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String pindex = request.getParameter("pageindex");
        if(pindex==null){ //第1页;
            pindex ="1";
        }
        Integer pagesize = 12;
        Integer pageindex = Integer.parseInt(pindex);
        String cid = request.getParameter("cid");
        if(cid==null){cid="1";}
        Pager<TbProduct> pageinfo =gs.goodsPager(pagesize, pageindex, cid);
        request.setAttribute("pageinfo", pageinfo);
        request.getRequestDispatcher("/my-all.jsp").forward(request, response);
    }
    protected void doPost(HttpServletRequest request,
                          HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
